home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / DocShell / DocUtilP.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  3.8 KB  |  143 lines  |  [TEXT/BROW]

  1. /*
  2.     File:        DocUtilP.cpp
  3.  
  4.     Contains:    Routines from DocUtils.cpp that are only used by the shell. They
  5.                 have been removed from DocUtils.cpp. DocUtils.cpp exposes
  6.                 private implementation of the shell, and we would like to
  7.                 remove the routines there from the public distribution.
  8.  
  9.     Owned by:    Nick Pilch
  10.  
  11.     Copyright:    1996 by Apple Computer, Inc., all rights reserved.
  12.  
  13.     Change History (most recent first):
  14.  
  15.          <2>     10/5/96    NP        Comments concerning changes to DocUtils.
  16.          <1>    18.09.1996    NP        first checked in
  17.  
  18.     To Do:
  19. */
  20.  
  21. #ifndef _DOCUTILP_
  22. #include "DocUtilP.h"
  23. #endif
  24.  
  25.  
  26. #ifndef SOM_Module_OpenDoc_StdProps_defined
  27. #include <StdProps.xh>
  28. #endif
  29.  
  30. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  31. #include <StdTypes.xh>
  32. #endif
  33.  
  34.  
  35. #ifndef SOM_ODDispatcher_xh
  36. #include "Disptch.xh"
  37. #endif
  38.  
  39.  
  40. #ifndef _DOCUTILS_
  41. #include "DocUtils.h"
  42. #endif
  43.  
  44. #ifndef _STORUTIL_
  45. #include "StorUtil.h"
  46. #endif
  47.  
  48. #ifndef _STDTYPIO_
  49. #include "StdTypIO.h"
  50. #endif
  51.  
  52. #ifndef _TEMPOBJ_
  53. #include "TempObj.h"
  54. #endif
  55.  
  56.  
  57. const  ODPropertyName kODPropTempDocument        =    "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Property:TempDocument";
  58.  
  59.  
  60. //------------------------------------------------------------------------------
  61. // ODGetFirstOpenDocument
  62. //------------------------------------------------------------------------------
  63.  
  64. ODDocument*    ODGetFirstOpenDocument(Environment* ev, ODSession* session)
  65. {
  66.     return ODGetNthOpenDocument(ev, session, 1);
  67. }
  68.                 
  69. //------------------------------------------------------------------------------
  70. // ODDeleteDocument
  71. //------------------------------------------------------------------------------
  72.  
  73. ODBoolean ODDeleteDocument(Environment* ev, ODSession* session, ODDocument* document)
  74. {
  75.     WASSERT(session != kODNULL);
  76.     WASSERT(document != kODNULL);
  77.  
  78.     if (!session)
  79.         THROW(kODErrIllegalNullInput);
  80.     if (!document)
  81.         THROW(kODErrIllegalNullDocumentInput);
  82.         
  83.     TempPlatformFile    currentFile = 
  84.         GetPlatformFileFromContainer(ev, document->GetContainer(ev));                            
  85.     ODBoolean retval = ODCloseDocument(ev, session, document);
  86.     currentFile->MoveToTrash();
  87.     return retval;
  88. }
  89.  
  90. //------------------------------------------------------------------------------
  91. // ODRevertDocument
  92. //------------------------------------------------------------------------------
  93.  
  94. void ODRevertDocument(Environment* ev, ODSession* session, ODDocument* document)
  95. {
  96.     WASSERT(session != kODNULL);
  97.     WASSERT(document != kODNULL);
  98.     if (!session)
  99.         THROW(kODErrIllegalNullInput);
  100.     if (!document)
  101.         THROW(kODErrIllegalNullDocumentInput);
  102.  
  103.     ODDraft* tempDraft = ODGetTempDraftFromOpenDocument(ev, session, document);
  104.     if (tempDraft)
  105.     {
  106.         ODCloseDraft(ev, session, tempDraft);    
  107.         tempDraft->RemoveChanges(ev);
  108.         ODOpenDraft(ev, session, tempDraft);
  109. //        SyncFileToProperties(ev, session, document);
  110.         session->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  111.     }
  112. }
  113.  
  114. //------------------------------------------------------------------------------
  115. // ODIsTempDocument
  116. //------------------------------------------------------------------------------
  117.  
  118. ODBoolean ODIsTempDocument(Environment* ev, ODSession* session, ODDocument* document)
  119. {
  120.     ODDraft* draft = ODGetTempDraftFromOpenDocument(ev, session, document);
  121.     RETURN_IF_NULL(draft, kODFalse);
  122.     TempODStorageUnit su = draft->AcquireDraftProperties(ev);
  123.     if (!su->Exists(ev, kODPropTempDocument, kODBoolean, 0))
  124.         return kODFalse;
  125.     return ODGetBooleanProp(ev, su, kODPropTempDocument, kODBoolean);
  126. }
  127.  
  128. //------------------------------------------------------------------------------
  129. // ODSetIsTempDocument
  130. //------------------------------------------------------------------------------
  131.  
  132. void ODSetIsTempDocument(Environment* ev, ODDraft* draft, ODBoolean isTemp)
  133. {
  134.     if (!draft)
  135.         return;
  136.     TempODStorageUnit su = draft->AcquireDraftProperties(ev);
  137.     if (isTemp)
  138.         ODSetBooleanProp(ev, su, kODPropTempDocument, kODBoolean, isTemp);
  139.     else
  140.         ODSURemoveProperty(ev, su, kODPropTempDocument);
  141. }
  142.  
  143.